package models.mappers;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import vos.RoleSearchVo;
import models.Operator;
import models.Role;
import models.Role;

public interface RoleMapper {
	/**
	 * 根据id查找角色
	 *
	 * @Title: findById 
	 * @param roleid 角色id
	 * @return
	 * @return: Role
	 */
	@Select("select * from "
			+ Role.TABLE_NAME
			+" where roleid=#{roleid} and isflag=0")
	Role findById(String roleid);
	/**
	 * 统计列表行数
	 *
	 * @Title: countHraDetail 
	 * @param vo
	 * @return
	 * @return: long
	 */
	long countRole(RoleSearchVo vo);
	/**
	 * 获取列表数据
	 *
	 * @Title: listHraStandard 
	 * @param vo
	 * @return
	 * @return: List<Standard>
	 */
	List<Role> listRole(RoleSearchVo vo);
	/**
	 * 批量启用角色
	 *
	 * @Title: betchEnable 
	 * @param listid 角色id列表
	 * @return
	 * @return: Boolean
	 */
	void betchEnable(Map<String, Object> map);
	/**
	 * 批量停用角色
	 *
	 * @Title: betchEnable 
	 * @param listid 角色id列表
	 * @return
	 * @return: Boolean
	 */
	void betchDisable(Map<String, Object> map);
	/**
	 * 批量删除角色
	 *
	 * @Title: betchDel 
	 * @param map
	 * @return: void
	 */
	void betchDel(Map<String, List<String>> map);
	/**
	 * 根据id删除角色
	 *
	 * @Title: delRole 
	 * @param id
	 * @return: void
	 */
	@Delete("delete from "
			+ Role.TABLE_NAME
			+" where roleid=#{id}")
	void delRole(String id);
	/**
	 * 根据id判断是否存在该角色
	 *
	 * @Title: checkCode 
	 * @param roleid
	 * @return
	 * @return: String
	 */
	@Select("select 1 from "
			+ Role.TABLE_NAME
			+" where roleid=#{roleid}")
	String checkCode(String roleid);
	/**
	 * 根据id获取角色信息
	 *
	 * @Title: getById 
	 * @param roleid 角色id
	 * @return
	 * @return: Role
	 */
	@Select("select * from "
			+ Role.TABLE_NAME
			+" where roleid=#{roleid}")
	Role getById(String roleid);
	/**
	 * 保存角色信息
	 *
	 * @Title: saveRole 
	 * @param role
	 * @return: void
	 */
	@Insert("insert into "
			+ Role.TABLE_NAME
			+" (roleid,rolename,isflag,createtime,createname) values"
			+ "(#{roleid},#{rolename},#{isflag},#{createtime},#{createname})")
	void saveRole(Role role);
	/**
	 * 更新角色信息
	 *
	 * @Title: updateRole 
	 * @param role
	 * @return: void
	 */
	@Update("update "
			+ Role.TABLE_NAME
			+" set rolename=#{rolename},"
			+ "isflag=#{isflag},modifyname=#{modifyname},modifytime=#{modifytime}"
			+ "where roleid=#{roleid}")
	void updateRole(Role role);
	/**
	 * 统计子表中用户数量
	 *
	 * @Title: countOperator 
	 * @param roleid 角色id
	 * @return
	 * @return: long
	 */
	@Select("select count(1) from role_user where roleid=#{roleid}")
	long countOperator(String roleid);
	/**
	 * 查询子表用户列表
	 *
	 * @Title: getOperator 
	 * @param vo
	 * @return
	 * @return: List<Operator>
	 */
	List<Operator> getOperator(RoleSearchVo vo);
	
}
